(ns minesweeper-tests
 (:use tejst.unit minesweeper ref.grid))

(deftest test-create-game
  (let [board-width 5
        board-height 10
        number-of-mines 10
        game (create-game board-width board-height number-of-mines)]
    (assert-not-nil game)
    (assert-equal board-width (width game))
    (assert-equal board-height (height game))
    (assert-equal number-of-mines (mine-count game))))

(deftest test-create-board-with-zero-mines
  (let [game (create-game 1 1 0)]
    (assert-equal 0 (mine-count game))))

(deftest test-reveal-with-mine
  (let [game (create-game 1 1 1)]
    (assert-equal :BOOM-GAME-OVER (reveal game 0 0))))

(deftest test-reveal-without-mine
  (let [game (create-game 2 1 0)]
    (assert-equal 0 (reveal game 0 0))))

(deftest test-create-with
  (let [only-mines (create-game-with 
                     [1 1])        
        no-mines (create-game-with 
                   [0 0])]
    
    (assert-equal :BOOM-GAME-OVER (reveal only-mines 0 0))
    (assert-equal 0 (reveal no-mines 0 0))))

(deftest test-reveal-with-surrounding-mines
  (let [game1 (create-game-with 
                [1 1 1 0]
                [1 0 1 0]
                [1 1 1 0])
        
        game2 (create-game-with 
                [0 1 1 0]
                [0 1 1 0]
                [0 1 1 0])]
    
    (assert-equal 8 (reveal game1 1 1))
    (assert-equal 2 (reveal game2 0 0))
    (assert-equal 3 (reveal game2 0 1))
    (assert-equal 2 (reveal game2 0 2))))

(deftest test-revealed-all-non-mines-wins-game
  (let [game (create-game-with [0 0 1])]
    (reveal game 0 0)
    (assert-equal :YOU-WIN (reveal game 1 0))))